<?php
Yii::import('zii.widgets.CBreadcrumbs');
class BreadcrumbsWidget extends CBreadcrumbs {

    /**
     * Initializes the widgets
     */
    public function init() {
        parent::init();
        
        $this->links=$this->controller->breadcrumbs;
        if($this->separator===null) $this->separator='<span class="separator">&gt;</span>';
    }

    /**
     * Execute the widgets
     */
    public function run() {
        Yii::beginProfile(get_class($this));

        if(empty($this->links))
                return;

        echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
        $links=array();
        if($this->homeLink===null){
                $label=Yii::t('zii','Home');
                $url=Yii::app()->homeUrl;
                $links[]=strtr($this->activeLinkTemplate,array(
                                '{url}'=>CHtml::normalizeUrl($url),
                                '{label}'=>$this->encodeLabel ? CHtml::encode($label) : $label,
                        ));
        
        }elseif($this->homeLink!==false)
                $links[]=$this->homeLink;
        foreach($this->links as $label=>$url)
        {
                if(is_string($label) || is_array($url))
                        $links[]=strtr($this->activeLinkTemplate,array(
                                '{url}'=>CHtml::normalizeUrl($url),
                                '{label}'=>$this->encodeLabel ? CHtml::encode($label) : $label,
                        ));
                else
                        $links[]=str_replace('{label}',$this->encodeLabel ? CHtml::encode($url) : $url,$this->inactiveLinkTemplate);
        }
        echo implode($this->separator,$links);
        echo CHtml::closeTag($this->tagName);     
        
        Yii::endProfile(get_class($this));
    }

}//end class
